import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import {
  CompanyPageQuery,
  GetCompanyInfoByIDRes,
  GetCompanyPageRes,
  GetHotCompanyRes,
} from './type'
import QueryString from 'qs'

enum COMPANY_API {
  GET_HOST_COMPANY = '/company/hot',
  GET_COMPANY_PAGE = '/company/more',
  GET_COMPANY_INFO_BYID = '/company/info/{id}',
}

/**
 * 求职者获取热门职位
 * @returns
 */
export const reqGetCompanyJob = () =>
  request.get<any, AxiosResponse<GetHotCompanyRes>>(
    COMPANY_API.GET_HOST_COMPANY,
  )

/**
 * 获取公司信息分页
 * @param {string} companyPageQuery 公司分页请求对象
 * @returns
 */
export const reqGetCompanyPage = (data: CompanyPageQuery) =>
  request.get<any, AxiosResponse<GetCompanyPageRes>>(
    COMPANY_API.GET_COMPANY_PAGE + '?' + QueryString.stringify(data),
  )

/**
 * 根据ID获取公司详细信息
 * @param {string} id
 * @returns
 */
export const reqGetCompanyInfoById = (id: number) =>
  request.get<any, AxiosResponse<GetCompanyInfoByIDRes>>(
    COMPANY_API.GET_COMPANY_INFO_BYID.replace('{id}', id.toString()),
  )
